package doudizhu2;

import java.util.*;

public class PokerGame {
    static HashMap<Integer,String> hm=new HashMap<>();
    static ArrayList<Integer> list=new ArrayList<>();

    static {
        String[] colour={"♥","♠","♣","♦"};
        String[] number={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        int serialnumber=1;
        for (String n : number) {

            for (String c : colour) {

            hm.put(serialnumber,c+n);
            list.add(serialnumber);
                serialnumber++;

            }
        }
        hm.put(serialnumber,"小王");
        list.add(serialnumber);
        serialnumber++;


        hm.put(serialnumber,"大王");
        list.add(serialnumber);
    }




    public PokerGame() {
        //2.洗牌
        Collections.shuffle(list);

        //3.发牌
        //3.1创建4个集合，接收牌
        //TreeSet可以排序
        TreeSet<Integer> lord=new TreeSet<>();
        TreeSet<Integer> player1=new TreeSet<>();
        TreeSet<Integer> player2=new TreeSet<>();
        TreeSet<Integer> player3=new TreeSet<>();
        //3.2遍历牌，发给每个人
        for (int i = 0; i < list.size(); i++) {
            Integer poker=list.get(i);
            if(i<=2){
                lord.add(poker);
                continue;
            }
            if(i%3==0){
                player1.add(poker);
            }
            else if(i%3==1){
                player2.add(poker);
            }
            else{
                player3.add(poker);
            }
        }


        //4.看牌(包括排序)
        showpoker("地主牌",lord);
        showpoker("player1",player1);
        showpoker("player2",player2);
        showpoker("player3",player3);

    }
    public void showpoker(String name,TreeSet<Integer> list){
        System.out.print(name+" : ");
        for (int s : list) {
            String poker = hm.get(s);
            System.out.print(poker+" ");
        }
        System.out.println();
    }
}
